package com.lbx.springcloud.controller;

import com.lbx.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author 吕兵星
 * @date 2020/11/8 16:20
 */
@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    private final static String PREFIX_URL="http://SPRINGCLOUD-PROVIDER";

    @GetMapping(value = "/consumer/getById/{id}",produces = {"application/json;charset=UTF-8"})
    public Dept getById(@PathVariable("id")Long id){
        return restTemplate.getForObject(PREFIX_URL+"/provider/getById/"+ id, Dept.class);
    }

    @GetMapping(value = "/consumer/getAll",produces = {"application/json;charset=UTF-8"})
    public List<Dept> getAll(){
        return restTemplate.getForObject(PREFIX_URL+"/provider/getAll", List.class);
    }

    @PostMapping(value = "/consumer/addDept",produces = {"application/json;charset=UTF-8"} )
    public Boolean addDept(Dept dept){
        return restTemplate.postForObject(PREFIX_URL + "/provider/addDept",dept,Boolean.class);
    }
}
